export default {
  data() {
    return {
			list: [],
			total: 0 as number,
			page: 1 as number,
			querys: {name: ''}
		}
  },
	// 下拉
	onReachBottom(){
		if(this.loadstate!=1 && this.page < Math.ceil(this.total / 10)){
			this.reachBottom()
		}
	},
	methods: {
		search (v: string) {
			this.querys.name = v
			this.page = 1
			this.reload()
		},
		reload(){
			this.loadstate = 1
			this.page = 1
			this.list = []
			return uni.$u.http.get(this.loadPath + this.$u.queryParams({...this.querys, page: this.page})).then((data: any)=>{
				this.loadData(data)
				this.loadstate = 2
			}).catch(()=>{})
		},
		// 加载更多方法
		reachBottom() {
			this.page += 1
			this.loadstate=1
			uni.$u.http.get((this.reachPath || this.loadPath) + this.$u.queryParams({...this.querys, page: this.page})).then((data: any)=>{
				this.loadstate=2
				for(const i in data){
					if(i == 'list'){
						this.list = this.list.concat(data.list)
					} else {
						Object.assign(this[i], data[i])
					}
				}
			})
		},
		toggle(i, field = 'exam'){
			if (this.querys[field] != i) {
				this.querys[field] = i
				this.reload()
			}
		}
	}
}
